/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actions;


import beans.ReadmarkLurkBean;
import client.TopicsPosts;
import dto.JfMembers;
import dto.Topics;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Amir
 */
public class ReadmarkLurkAction extends org.apache.struts.actions.DispatchAction {
    
    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
   
    public ActionForward readmark(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward=new ActionForward();
        TopicsPosts posts=new TopicsPosts();
        Topics topic=new Topics();
       Integer topicid =new Integer(request.getParameter("topicid"));
        topic.setTopicid(topicid);
       
       JfMembers member = (JfMembers)request.getSession().getAttribute("userBean");
        System.out.println(member.getMemberId()+"member");

       topic= posts.getTopic(topic);
       System.out.println(topic.getTopicid()+"topic");
        boolean flag=posts.readmark(topic,member);


        if(flag==true)
        {
            ((ReadmarkLurkBean)form).setReadmarkStatus(true);
           
        }

            forward=mapping.findForward("done");
        return forward;
    }

     public ActionForward lurk(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward=new ActionForward();
        TopicsPosts posts=new TopicsPosts();
        Topics topic=new Topics();
       Integer topicid =new Integer(request.getParameter("topicid"));
        System.out.println(topicid);
        topic.setTopicid(topicid);
       topic= posts.getTopic(topic);
        boolean flag=posts.lurk(topic);

        if(flag==true)
        {
           
            forward=mapping.findForward("done");
        }
         else
        {

        }

        return forward;
    }
}
